home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
MCASM.RAR
/
MC_ASM.EXE
/
WROX_ASM
/
CH12
/
COMMON
/
MANAGER.H
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-24
|
4KB
|
106 lines
/*
* This program is a simple expanded/extanded memory manger
* It lets you to allocate and use memory blocks of any size
* (but normally they should be at least 200 byte per block)
* Each block takes about 16 bytes of conventional memory
* and manager takes 64K expanded/extanded memory for its
* internal needs
* Written by Podvoysky E. & Kiselev J. CZ 1994.
*/
// !!!!!!!!! Attention !!!!!!!!!!!!
#define EMM
/*
* if you want to use this program with EMM386.SYS driver
* please, uncomment line " #define EMM "
* I don't know why, but normal version of
* our program doesn't work with this particular driver
*/
/* Low-level routines support both XMS and EMS protocols, so
* you need not to trouble about it.
* Ask XMS/EMS drivers to make as more handles as possible
* you may take only (64*numhandles) kilobytes of memory
* You MUST call manager_initialize() before using memory,
* and (it's important!!!!) manager_finish(TRUE) at the end
* of your program ( to return taken extended memory to system)
*/
#ifndef MANAGER_H
#define MANAGER_H
#include "common.h"
#define NEAR far
#define FAR huge
#define SIZE_TYPE long
#define USER_HANDLE WORD
#define NULL_HANDLE 0xFFFFU
//------------- high - level routines
int manager_initialize(); // don't forget to call it!
// returns -1 if error occured
void manager_finish(BOOL dispose_conv);
// allocate memory block
// returns USER_HANDLE you will use as identifier of the block
// returns NULL_HANDLE if error occured
USER_HANDLE EXM_alloc(SIZE_TYPE size);
// Remember! Each block eates about 16 bytes of conventional memory
// free memory block
int EXM_free(USER_HANDLE handle); // returns -1 if error occured
// move from ex... (extra!) memory to conventional
int EXM_move_to_conv(void FAR *dest, USER_HANDLE source_handle,
SIZE_TYPE offset, SIZE_TYPE size);
// returns -1 if error occured
// move from conventional memory to extra
int EXM_move_to_ext(USER_HANDLE dest_handle, void FAR *source,
SIZE_TYPE offset, SIZE_TYPE size);
// returns -1 if error occured
int EXM_to_EXM(USER_HANDLE dest_handle, SIZE_TYPE dest_offset,
USER_HANDLE source_handle, SIZE_TYPE source_offset,
SIZE_TYPE size);
// returns -1 if error occured
long EXM_coreleft(); //available extended memory in bytes
// may report more, than ypu really may get
// if XMS/EMM driver doesn't provides enough handles
// manager use handles of 64K size
extern BOOL EXM_initialized;
extern int EXM_error;
/* 0 - Ok
* < 0 - returned system errors
* 1 - not enough conventional memory
* 2 - not enough extra memory
* 3 - invalide user handle
* 4 - attempt to read/write beyond end of allocated block
* 5 - invalid parameter in routine call (e.g.: allocate -1000 bytes )
* 10 - manager was not initialized
* 100 - some error reported by low-level system
* 101 - internal structure error (invalid handle)
* 102 - internal structure error (free marking)
* 103 - internal structure error (size of block and offset in handle)
*/
/* low - level procedures */
extern "C" int init_ext_mem();
extern "C" int get_free_ext_mem(void);
extern "C" int alloc_ext_mem(int);
extern "C" int free_ext_mem(int);
extern "C" int move_ext_mem(int handle,WORD offset,WORD size,
void* real_address,BYTE direction_flag);
// direction_flag 0 - from conventional to extra
// 1 - from extra to conventional
extern "C" int move_ext2ext(int dest_handle,int dest_offset,
int source_handle,int source_offset,int size);
#endif